package com.ecoolex.discount.sales.core.manager;

import com.ecoolex.discount.sales.core.dao.DiscountOrderOutinfoDAO;
import com.ecoolex.discount.sales.entity.DiscountOrderOutinfo;
import com.ecoolex.discount.sales.pojo.CreateOrderChannelDTO;

import java.time.Instant;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DiscountOrderOutinfoManager {
	
    @Autowired
    private DiscountOrderOutinfoDAO dao;
    
    public void add(Integer orderId,CreateOrderChannelDTO channel,String createUser) {
    	DiscountOrderOutinfo record = new DiscountOrderOutinfo();
    	record.setOrderId(orderId);
    	record.setChannel(channel.getChannelId());
    	record.setOutId(channel.getOutId());
    	record.setDeleted(DiscountOrderOutinfo.NOT_DELETED);
    	record.setCreateUser(createUser);
    	record.setCreateTime(Date.from(Instant.now()));
    	record.setUpdateUser(createUser);
    	record.setUpdateTime(Date.from(Instant.now()));
    	dao.insert(record);
    }
    
    public DiscountOrderOutinfo getByOrderId(Integer orderId) {
    	return dao.selectByPrimaryKeyWithLogicalDelete(orderId, DiscountOrderOutinfo.NOT_DELETED);
    }
}